package core.result;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
@ApiModel(value = "JsonResult", description = "统一返回JSON格式数据")
public class JsonResult {

    @ApiModelProperty("响应的code代码")
    private Integer code;

    @ApiModelProperty("响应是否成功")
    private Boolean success;

    @ApiModelProperty("响应消息")
    private String message;

    @ApiModelProperty("响应的data代码")
    private Object data;

    public JsonResult (Integer code, Boolean success, String message, Object data) {
        this.code = code;
        this.success = success;
        this.message = message;
        this.data = data;
    }

    public static JsonResult ok () {
        JsonResult result = new JsonResult(200, true, "成功", null);
        return result;
    }

    public static JsonResult ok (Object data) {
        JsonResult result = new JsonResult(200, true, "成功", data);
        return result;
    }

    public static JsonResult error () {
        JsonResult result = new JsonResult(500, false, "失败", null);
        return result;
    }

    public static JsonResult error (String message) {
        JsonResult result = new JsonResult(500, false, message, null);
        return result;
    }

}
